﻿using System.Reflection;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.VersionControl.Controls;

namespace TfsComLib.FolderDiff
{
    public class FolderDiffInv
    {
        public FolderDiffInv(VersionControlServer versionControlServer, ItemIdentifier item1, int version1,
            ItemIdentifier item2, int version2)
        {
            var controlsAssembly = Assembly.GetAssembly(typeof (ControlAddItemsExclude));
            var dialogFolderDiffType =
                controlsAssembly.GetType("Microsoft.TeamFoundation.VersionControl.Controls.FolderDiff");
            // invoce constructor
            //internal FolderDiff(string path1, VersionSpec spec1, string path2, VersionSpec spec2, VersionControlServer server, RecursionType recursion);
            var ci = dialogFolderDiffType.GetConstructor(
                BindingFlags.Instance | BindingFlags.NonPublic,
                null,
                new[]
                {
                    typeof (string), typeof (VersionSpec), typeof (string), typeof (VersionSpec),
                    typeof (VersionControlServer), typeof (RecursionType)
                },
                null);
            var spec1 = VersionSpec.ParseSingleSpec("C" + version1, null);
            var spec2 = VersionSpec.ParseSingleSpec("C" + version2, null);
            FolderDiffObject =
                ci.Invoke(new object[] {item1.Item, spec1, item2.Item, spec2, versionControlServer, RecursionType.Full});
        }

        /// <summary>
        ///     internal FolderDiff(string localPath, VersionControlServer server, RecursionType recursion);
        /// </summary>
        /// <param name="versionControlServer"></param>
        /// <param name="localPath"></param>
        public FolderDiffInv(VersionControlServer versionControlServer, string localPath)
        {
            var controlsAssembly = Assembly.GetAssembly(typeof (ControlAddItemsExclude));
            var dialogFolderDiffType =
                controlsAssembly.GetType("Microsoft.TeamFoundation.VersionControl.Controls.FolderDiff");
            // invoce constructor
            //internal FolderDiff(string path1, VersionSpec spec1, string path2, VersionSpec spec2, VersionControlServer server, RecursionType recursion);
            var ci = dialogFolderDiffType.GetConstructor(
                BindingFlags.Instance | BindingFlags.NonPublic,
                null,
                new[] {typeof (string), typeof (VersionControlServer), typeof (RecursionType)},
                null);
            FolderDiffObject = ci.Invoke(new object[] {localPath, versionControlServer, RecursionType.Full});
        }

        public object FolderDiffObject { get; set; }
    }
}